<template>
    <div class="app-container">

      <!-- 添加或修改短信对话框 -->
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="接收号码" prop="ssPhone">
            <el-input v-model="form.ssPhone" placeholder="请输入接收号码" />
          </el-form-item>
          <el-form-item label="消息内容" prop="ssMessage">
            <el-input v-model="form.ssMessage" type="textarea" placeholder="请输入内容" />
          </el-form-item>
          <el-form-item label="定时发送" prop="ssSetTime">
            <el-date-picker clearable
              v-model="form.ssSetTime"
              type="datetime"
              value-format="yyyy-MM-dd hh:mm:ss"
              placeholder="请选择定时发送">
            </el-date-picker>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
    </div>
  </template>
  
  <script>
  import { listSms, getSms, delSms, addSms, updateSms } from "@/api/system/sms";
  
  export default {
    name: "Sms",
    dicts: ['sys_job_status'],
    data() {
      return {
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          ssPhone: [
            { required: true, message: "接收号码不能为空", trigger: "blur" }
          ],
          ssMessage: [
            { required: true, message: "消息内容不能为空", trigger: "blur" }
          ],
        }
      };
    },
    methods: {
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          ssId: null,
          ssPhone: null,
          ssMessage: null,
          ssSetTime: null,
          ssState: null,
          ssSendTime: null,
          ssResult: null,
          updateTime: null,
          createTime: null,
          createBy: null,
          updateBy: null
        };
        this.resetForm("form");
      },
     
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.ssId != null) {
              updateSms(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addSms(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
    }
  };
  </script>
  